home *** CD-ROM | disk | FTP | other *** search
- #ifndef H_OOF3
- #define H_OOF3
-
- // COPYRIGHT 1994 A.D. Software, All rights reserved
-
- // OOFILE database non-numeric field-related classes
- // see also oof4.hpp
-
- #include "oof1.hpp"
- #ifdef _Macintosh
- #include <Types.h>
- #endif
-
- enum OOF_fieldTypes {charField, textField, dateField, shortField, uShortField, longField, uLongField, realField, blobField, compoundField, boolField, fixedBinaryField};
- ostream& operator<<(ostream&, OOF_fieldTypes);
-
- class dbField : public dbClass, public OOF_mixRelChainEndPoint{
- public:
- dbField() ;
- dbField(const OOF_IndexOptions) ;
- dbField(const char *) ;
- dbField(const char *, const OOF_IndexOptions);
- dbField(const dbField&);
- virtual ~dbField() {};
-
- // operator dbField*();
-
- // additional setting operators
- void index(const OOF_IndexOptions=kIndexed);
- void setName(const char* name);
-
- // reflective operators
- virtual void describe(ostream&);
- virtual unsigned int countSegments() const;
- virtual OOF_fieldTypes fieldType() const=0;
- virtual unsigned long fieldLen() const=0;
- virtual unsigned int fieldEditLen() const;
- dbTable* fieldTable() const;
- unsigned long fieldDataLen() const;
- fieldNumT fieldNumber() const;
- OOF_String fieldName() const;
- OOF_IndexOptions fieldIndexOptions() const;
- bool fieldIndexAllowsDups() const;
- bool fieldIndexIsCompressLeading() const;
- bool fieldIndexIsCompressPadding() const;
- virtual bool fieldIsIndexed() const;
- virtual bool fieldIsUniqueIndexed() const;
- unsigned int fieldNumIndexes() const;
- bool allowsDuplicates() const;
- bool caseSensitive() const;
- virtual bool fieldIsBlob() const;
- virtual bool fieldIsBinary() const;
- virtual bool fieldIsVirtual() const;
-
- // data access
- virtual void setString(const char*) { assert(0); };
- void operator=(const char*);
- virtual char *copyAsChars();
- const void* binaryContents();
- const void* currentbinaryContents() const;
- virtual void extract(ostream&);
- virtual bool insert(istream&, char fieldSep, char recSep);
- virtual void copyValueFrom(dbField*) {};
- virtual bool validateContents() { return true; };
-
- virtual void generateTestData(const char *testBuf, unsigned long testBufLen) {};
-
-
- protected:
- void validateContextInCaseRelated();
- dbField* GetRelatedFieldOrUs();
-
- // data storage
- OOF_tableBackend *mBackend;
- dbTable* mTable;
- unsigned int mFieldNumber;
-
- private:
- OOF_IndexOptions mIndexOptions;
- OOF_String mFieldName;
-
- friend class dbTable;
- friend void validateDatabaseState();
- };
- typedef dbField *dbFieldPtr;
-
-
-
- class dbQueryBinary;
- class dbQueryTrinary;
- class dbQueryBinaryCombo;
-
- class dbChar : public dbField {
- public:
- // constructors
- dbChar(long fieldWidth = 80) :
- mMaxLength(fieldWidth) {};
- dbChar(long fieldWidth, const char *fieldName):
- dbField(fieldName),
- mMaxLength(fieldWidth){};
- dbChar(long fieldWidth, const OOF_IndexOptions indexOptions) :
- dbField(indexOptions),
- mMaxLength(fieldWidth) {};
- dbChar(long fieldWidth, const char *fieldName, const OOF_IndexOptions indexOptions) :
- dbField(fieldName, indexOptions),
- mMaxLength(fieldWidth) {};
- virtual ~dbChar() {};
-
- // reflective operators
- virtual void describe(ostream&);
- virtual OOF_fieldTypes fieldType() const;
- virtual bool fieldIsBinary() const;
- virtual unsigned long fieldLen() const;
-
- // search factories
- dbQueryBinary operator==(const char*) const;
- dbQueryBinary operator<(const char*) const;
- dbQueryBinary operator<=(const char*) const;
- dbQueryBinary operator>=(const char*) const;
- dbQueryBinary operator>(const char*) const;
- dbQueryBinary operator!=(const char*) const;
- dbQueryBinary startsWith(const char*) const;
- dbQueryTrinary between(const char*, const char*) const;
- dbQueryTrinary outside(const char*, const char*) const;
-
- // data access
- dbChar& operator()();
- virtual char * copyAsChars();
- operator const char*();
- #ifdef _Macintosh
- void asStr255(Str255 s);
- void setStr255(const Str255 s);
- #endif
- virtual void setString(const char*);
- dbChar& operator=(const char*);
- void setChars(const char* str , unsigned long charLen);
- dbChar& operator=(dbChar&);
- virtual void extract(ostream& os);
- virtual bool insert(istream&, char fieldSep, char recSep);
-
- virtual void generateTestData(const char *testBuf, unsigned long testBufLen);
-
- // data storage
- private:
- long mMaxLength;
- };
-
-
-
- class dbBLOB : public dbField {
- public:
- // constructors
- dbBLOB() :
- mBody(0),
- mBodyLength(0),
- mDirty(false),
- mLoaded(false)
- {};
- dbBLOB(const OOF_IndexOptions indexOptions) :
- dbField(indexOptions),
- mBody(0),
- mBodyLength(0),
- mDirty(false),
- mLoaded(false)
- {};
- dbBLOB(const char *fieldName) :
- dbField(fieldName),
- mBody(0),
- mBodyLength(0),
- mDirty(false),
- mLoaded(false)
- {};
- dbBLOB(const char *fieldName, const OOF_IndexOptions indexOptions) :
- dbField(fieldName, indexOptions),
- mBody(0),
- mBodyLength(0),
- mDirty(false),
- mLoaded(false)
- {};
- dbBLOB(const dbBLOB& rhs) :
- mBody(0),
- mBodyLength(0),
- mDirty(false),
- mLoaded(false)
- {};
- virtual ~dbBLOB();
-
- // reflective operators
- virtual OOF_fieldTypes fieldType() const;
- virtual unsigned long fieldLen() const;
- virtual bool fieldIsBlob() const;
- bool isDirty() const;
-
- // data access
- dbBLOB& operator()();
- void *bodyAddress() const;
- void reset();
- void* allocRoomFor(unsigned long);
- void *orphanBody();
- void adoptBody(void* body, unsigned long bodyLen);
-
- protected:
- void SetLength(unsigned long len);
- void LoadField();
-
- // data storage
- void* mBody; // owned
- unsigned long mBodyLength; // allow for part-using the block
- bool mDirty,mLoaded;
-
-
- };
-
-
- class dbText : public dbBLOB {
- public:
- // constructors
- dbText(){};
- dbText(const OOF_IndexOptions opt) :
- dbBLOB(opt)
- {
- // assert( opt == kNotIndexed); // more later
- };
- dbText(const char *fieldName) :
- dbBLOB(fieldName) {};
- dbText(const char *fieldName, const OOF_IndexOptions opt) :
- dbBLOB(fieldName, opt) {//assert(opt == kNotIndexed);
- };
- virtual ~dbText() {};
-
- // reflective operators
- virtual OOF_fieldTypes fieldType() const;
- virtual bool fieldIsBinary() const;
-
- // search factories
- dbQueryBinary operator==(const char*) const;
- dbQueryBinary operator<(const char*) const;
- dbQueryBinary operator<=(const char*) const;
- dbQueryBinary operator>=(const char*) const;
- dbQueryBinary operator>(const char*) const;
- dbQueryBinary operator!=(const char*) const;
-
- // data access
- dbText& operator()();
- virtual char * copyAsChars();
- operator const char*();
- virtual void setString(const char*);
- dbText& operator=(const char*);
- dbText& operator=(dbText&);
- void operator+=(const char*); // the only field with an append operator
- void setChars(const char* str , unsigned long charLen);
- virtual void extract(ostream& os);
-
- virtual void generateTestData(const char *testBuf, unsigned long testBufLen);
- };
-
-
- class dbFixedBinary : public dbField {
- public:
- // constructors
- dbFixedBinary(long fieldWidth = 4) :
- mBodyLength(fieldWidth) {};
- dbFixedBinary(long fieldWidth, const OOF_IndexOptions indexOptions) :
- dbField(indexOptions),
- mBodyLength(fieldWidth) {};
- dbFixedBinary(long fieldWidth, const char *fieldName) :
- dbField(fieldName),
- mBodyLength(fieldWidth) {};
- dbFixedBinary(long fieldWidth, const char *fieldName, const OOF_IndexOptions indexOptions) :
- dbField(fieldName, indexOptions),
- mBodyLength(fieldWidth) {};
- dbFixedBinary& operator=(dbFixedBinary& rhs);
-
- virtual ~dbFixedBinary() {};
-
- // reflective operators
- virtual OOF_fieldTypes fieldType() const;
- virtual unsigned long fieldLen() const;
-
- // data access
- dbFixedBinary& operator()();
- dbFixedBinary& operator=(const char* str);
- virtual void setString(const char*);
- void setValue(const void* str);
- void setByte(char c, unsigned int offset);
- virtual void extract(ostream& os);
- virtual void generateTestData(const char *testBuf, unsigned long testBufLen);
- virtual void describe(ostream& os);
-
- protected:
-
- // data storage
- unsigned long mBodyLength;
-
-
- };
-
-
- class dbCompoundField : public dbField {
- public:
- // constructors
- dbCompoundField() :
- mNumSegments(0),
- mTotalLength(0) {};
- dbCompoundField(const OOF_IndexOptions indexOptions) :
- dbField(indexOptions),
- mNumSegments(0),
- mTotalLength(0) {};
- dbCompoundField(const char *fieldName) :
- dbField(fieldName),
- mNumSegments(0),
- mTotalLength(0) {};
- dbCompoundField(const char *fieldName, const OOF_IndexOptions indexOptions) :
- dbField(fieldName, indexOptions),
- mNumSegments(0),
- mTotalLength(0) {};
- virtual ~dbCompoundField() {};
-
- virtual unsigned int countSegments() const;
- void addSegment(dbField&);
- dbCompoundField& operator<<(dbField&);
-
- // data output
- virtual void extract(ostream& os);
-
- // reflective operators
- virtual OOF_fieldTypes fieldType() const;
- virtual unsigned long fieldLen() const;
- virtual bool fieldIsVirtual() const;
- const dbField* segment(unsigned int) const;
-
- // search factories
- dbQueryBinary operator==(const char*) const;
- dbQueryBinary operator<(const char*) const;
- dbQueryBinary operator<=(const char*) const;
- dbQueryBinary operator>=(const char*) const;
- dbQueryBinary operator>(const char*) const;
- dbQueryBinary operator!=(const char*) const;
- dbQueryBinary startsWith(const char* str) const;
-
- // data storage
- private:
- unsigned int mNumSegments, mTotalLength;
- OOF_Dictionary mSegments;
- };
-
-
-
- // include inline definitions
- #include "oof3.inl"
- #endif
-